python

您所在的位置:网站首页 K-prototypes Python代码 python

python

2024-06-12 05:24| 来源: 网络整理| 查看: 265

问题描述

我正在尝试对混合数据(分类和数字)执行 k 原型聚类。我的输入文件是一个 csv,它看起来像这样(它包含 300000 行):

Unnamed: 0.1,market,vendor_name,price,ship_from,category_cl 0,mark,03welle,1.79367196,DE,Drugs 1,aruna,03welle,0.05880975,DE,Drugs 2,ny,03welle,0.11344859,DE,Drugs 3,mi,03welle,0.18655316,DE,Drugs

我正在尝试实现 k-prototypes 聚类,因为可以聚类混合数据。问题是我遇到了一个错误,我无法理解它(当然要修复它)。我正在使用我在相关仓库中找到的代码:

import numpy as np print("initialising") syms = np.genfromtxt('pameteliko.csv', dtype=str, delimiter='\t')[:, 0] print("******") print(syms) X = np.genfromtxt('pameteliko.csv', dtype=object, delimiter='\t')[:, 1:] print("################") X[:, 0] = X[:, 0].astype(float) from kmodes.kprototypes import KPrototypes kproto = KPrototypes(n_clusters=6, init='Cao', verbose=2) clusters = kproto.fit_predict(X, categorical=[1, 2]) #Print cluster centroids of the trained model. print(kproto.cluster_centroids_) #Print training statistics print(kproto.cost_) print(kproto.n_iter_)

(打印件用于调试目的)。我收到以下错误:

IndexError: too many indices for array

syms我对和也有一些疑问X。任何帮助将非常感激。

标签: pythonk-meanscategorical-data



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3